package com.liupf.common;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.ext.handler.UrlSkipHandler;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.liupf.controller.CategoryOrderController;
import com.liupf.controller.CompanyController;
import com.liupf.controller.DriverController;
import com.liupf.controller.InvoiceController;
import com.liupf.controller.LoginController;
import com.liupf.controller.MapController;
import com.liupf.controller.MemberController;
import com.liupf.controller.MyController;
import com.liupf.controller.NewOrderController;
import com.liupf.controller.NoticeController;
import com.liupf.controller.OperatorController;
import com.liupf.controller.OrderController;
import com.liupf.controller.ParkController;
import com.liupf.controller.PriceRuleController;
import com.liupf.controller.RechargeController;
import com.liupf.controller.SysUserController;
import com.liupf.controller.UserPointController;
import com.liupf.controller.VipMemberController;
import com.liupf.domain.BBalanceChangeLog;
import com.liupf.domain.BUserEnroll;
import com.liupf.domain.City;
import com.liupf.domain.CompanyPrice;
import com.liupf.domain.DeliveryPrice;
import com.liupf.domain.Driver;
import com.liupf.domain.DriverPoint;
import com.liupf.domain.DriverPointRule;
import com.liupf.domain.Invoice;
import com.liupf.domain.Member;
import com.liupf.domain.MemberDeposit;
import com.liupf.domain.MembersTel;
import com.liupf.domain.Notice;
import com.liupf.domain.OperatorLog;
import com.liupf.domain.Order;
import com.liupf.domain.OrderJob;
import com.liupf.domain.OrderTrajectory;
import com.liupf.domain.ParkPrice;
import com.liupf.domain.Recharge;
import com.liupf.domain.SysUser;
import com.liupf.domain.Tel;
import com.liupf.domain.TelCompanyDedut;
import com.liupf.domain.TelCompanyRecharge;
import com.liupf.domain.TelPrice;
import com.liupf.domain.TelPriceRule;
import com.liupf.domain.Terminal;
import com.liupf.domain.UserPoint;
import com.liupf.interceptor.AuthInterceptor;
import com.liupf.interceptor.ExceptionInterceptor;
import com.liupf.interceptor.FreemarkerInterceptor;
import com.liupf.interceptor.SessionInViewInterceptor;

/**
 * @description 基础配置信息
 * @author shevliu
 * @email shevliu@gmail.com Jul 26, 2012 9:26:46 PM
 */
public class BaseConfig extends JFinalConfig {
	

	/**
	 * 
	 */
	@Override
	public void configConstant(Constants me) {
		loadPropertyFile("classes/config.properties");
		me.setFreeMarkerViewExtension(".ftl");
		me.setBaseViewPath("WEB-INF/pages");
		me.setDevMode(false);
	}

	@Override
	public void configHandler(Handlers me) {
		
		 me.add(new UrlSkipHandler("/groupAssignment.html", false));
	}

	@Override
	public void configInterceptor(Interceptors me) {
		me.add(new AuthInterceptor());
		me.add(new ExceptionInterceptor());
		me.add(new SessionInViewInterceptor());
		me.add(new FreemarkerInterceptor());
	}

	@Override
	public void configPlugin(Plugins me) {
		
		
		
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password"));
		me.add(c3p0Plugin);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		arp.addMapping("sys_user", SysUser.class);	
		arp.addMapping("driver_member", Member.class);	
		arp.addMapping("driver_member_deposit", MemberDeposit.class);
		arp.addMapping("driver_members_telephone", MembersTel.class);
		arp.addMapping("b_user", Driver.class);	
		arp.addMapping("order_detail", Order.class);	
		arp.addMapping("recharge", Recharge.class);	
		arp.addMapping("order_trajectory", OrderTrajectory.class);	
		arp.addMapping("notice", Notice.class);	
		arp.addMapping("order_job", OrderJob.class);	
		arp.addMapping("tel_company", Tel.class);
		arp.addMapping("tel_price", TelPrice.class);
		arp.addMapping("tel_price_rule", TelPriceRule.class);
		arp.addMapping("invoice", Invoice.class);
		arp.addMapping("b_user_point_log", DriverPoint.class);
		arp.addMapping("operator_log", OperatorLog.class);
		arp.addMapping("b_user_point_rule", DriverPointRule.class);
		arp.addMapping("b_user_balance_change", BBalanceChangeLog.class);
		arp.addMapping("user_point", UserPoint.class);
		
		arp.addMapping("b_city", City.class);
		arp.addMapping("b_terminal", Terminal.class);
		arp.addMapping("b_delivery_price", "delivery_id", DeliveryPrice.class);
		arp.addMapping("tel_company_price", CompanyPrice.class);
		arp.addMapping("b_park_price", ParkPrice.class);
		arp.addMapping("tel_company_recharge", TelCompanyRecharge.class);
		arp.addMapping("b_user_enroll", BUserEnroll.class);
		arp.addMapping("tel_company_dedut", TelCompanyDedut.class);
		arp.setShowSql(false);
	}

	@Override
	public void configRoute(Routes me) {
		me.add("/" , LoginController.class);
		me.add("/my" , MyController.class);
		me.add("/map", MapController.class);
		me.add("/sysUser" , SysUserController.class);
		me.add("/member" , MemberController.class);
		me.add("/driver" , DriverController.class);
		me.add("/order" , OrderController.class);
		me.add("/recharge" , RechargeController.class);
		me.add("/notice" , NoticeController.class);
		me.add("/invoice" , InvoiceController.class);
		me.add("/operator" , OperatorController.class);
		me.add("/categoryorder" , CategoryOrderController.class);
		me.add("/pricerule" , PriceRuleController.class);
		me.add("/vipmember" , VipMemberController.class);
		me.add("/newOrder" , NewOrderController.class);
	    me.add("/park", ParkController.class);
	    me.add("/company",CompanyController.class);
	    me.add("/userpoint",UserPointController.class);

	}

}
